package jmine.tec.web.wicket.pages.example.crud;

import java.util.List;

import jmine.tec.report.impl.table.ReportTableBuilder;
import jmine.tec.web.wicket.dao.WebTestEntityDAO;
import jmine.tec.web.wicket.domain.WebTestEntity;
import jmine.tec.web.wicket.mock.MockMessageCreator;
import jmine.tec.web.wicket.pages.example.form.FormPageExample;
import jmine.tec.web.wicket.pages.form.CrudPage;
import jmine.tec.web.wicket.pages.form.FormType;

import org.apache.wicket.Page;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.WebMarkupContainer;

import bancosys.tec.exception.MessageCreator;
import bancosys.tec.persist.dao.BaseDAOFactory;

/**
 * Página de exemplo de CRUD.
 * 
 * @author Rafael Volpato
 * @date Nov 10, 2011
 */
public class CrudPageExample extends CrudPage<WebTestEntity> {

    /**
     * {@inheritDoc}
     */
    public Page createNewPage() {
        return new FormPageExample(new PageParameters(), this);
    }

    /**
     * {@inheritDoc}
     */
    public List<WebTestEntity> search(BaseDAOFactory daoFactory) {
        WebTestEntityDAO dao = daoFactory.getDAOByClass(WebTestEntityDAO.class);
        WebTestEntity model = this.getModel();
        return dao.findByMnemonicoData(model.getMnemonico(), model.getData());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected Page createFormPage(WebTestEntity entity, FormType formType) {
        return new FormPageExample(this, new PageParameters(), entity, formType);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void addSearchFields(WebMarkupContainer container) {
        container.add(this.createTextField("mnemonico"));
        container.add(this.createDateField("data"));
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void addResultTableColumns(ReportTableBuilder<WebTestEntity> table) {
        table.addStringColumn("nome", "Nome", "nome");
        table.addStringColumn("mnemonico", "Mnemônico", "mnemonico");
        table.addDateColumn("data", "Data", "data");
        table.addNumberColumn("valor", "Valor", "valor", 2);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected MessageCreator getHelpTextCreator() {
        return new MockMessageCreator();
    }
}